//package org.csu.mypetstore.controller.admin;
//
//import org.csu.mypetstore.domain.PO.*;
//import org.csu.mypetstore.domain.VO.AccountVO;
//import org.csu.mypetstore.service.AccountService;
//import org.csu.mypetstore.service.OrderService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.ui.Model;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.ArrayList;
//import java.util.Iterator;
//import java.util.List;
//
//@Controller
//@SessionAttributes(value = {"admin"})
//public class AdminAccountController {
//
//
//    @Autowired
//    AccountService accountService;
//    @Autowired
//    OrderService orderService;
//    Admin admin;
//
//    //跳转至登录界面
//    @GetMapping("/viewSignonAdmin")
//    public String viewSignonAdmin(Model model){
//        Admin loginAdmin = (Admin) model.getAttribute("admin");
//        if (loginAdmin == null){
//            return "admin/AdminLogin";
//        }
//        return "admin/viewAdmin";
//    }
//
//    @ResponseBody
//    @GetMapping("/getAllAccount")
//    public List<Account> getAllAccount(Model model){
//        Admin loginAdmin = (Admin) model.getAttribute("admin");
//        if (loginAdmin != null && loginAdmin.getAdminname() != null){
//            //获取所有account
//
//            List<AccountVO> accountVOList = accountService.getAccountList();
//            Iterator<AccountVO> accountIterator = accountVOList.listIterator();
//            List<Account> accountList = new ArrayList<>();
//            while (accountIterator.hasNext()){
//                accountList.add(accountIterator.next().getAccount());
//            }
//            return accountList;
//        }
//        return null;
//    }
//
//    //退出登陆的时候设置管理员为空，返回登陆界面
//    @GetMapping("/signOutAdmin")
//    public String signOutAdmin(Model model){
//        model.addAttribute("admin", new Admin());
//        return "admin/AdminLogin";
//    }
//
//    //admin登录
//    //用户信息查看跳转
//    @PostMapping("/signonAdmin")
//    public String signonAdmin(String username,String keyword,Model model){
//        admin = accountService.getAdminByAdminnameAndKeyword(username,keyword).getData();
//        if(admin != null){
//            model.addAttribute("admin", admin);
//            return "admin/viewAdmin";
//        }else{
//            model.addAttribute("msg","用户名或密钥错误，请重新登录");
//            return "admin/AdminLogin";
//        }
//    }
//
//    @PostMapping("/adminEditAccount")
//    @ResponseBody
//    public void adminEditAccount(String username,String email,String firstName,String lastName,String status,String addr1,String addr2,
//                                 String city,String state,String zip,String country,String phone, Model model){
//        Admin loginAdmin = (Admin) model.getAttribute("admin");
//        if (loginAdmin != null && loginAdmin.getAdminname() != null){
//            Account account = new Account();
//            account.setPhone(phone);
//            account.setZip(zip);
//            account.setCity(city);
//            account.setAddress2(addr2);
//            account.setAddress1(addr1);
//            account.setEmail(email);
//            account.setUsername(username);
//            account.setCountry(country);
//            accountService.updateAccount(account);
//        }
//    }
//
//    @PostMapping("/adminDeleteAccount")
//    @ResponseBody
//    public void adminDeleteAccount(String username, Model model){
//        Admin loginAdmin = (Admin) model.getAttribute("admin");
//        if (loginAdmin != null && loginAdmin.getAdminname() != null){
//            accountService.deleteAccountByUsername(username);
//        }
//    }
//
//    @PostMapping("/adminAddAccount")
//    @ResponseBody
//    public void adminAddAccount(String username, Model model){
//        Admin loginAdmin = (Admin) model.getAttribute("admin");
//        if (loginAdmin != null && loginAdmin.getAdminname() != null){
//            AccountVO accountVO = new AccountVO();
//            Account account = new Account();
//            accountVO.setAccount(account);
//            Signon signon = new Signon();
//            accountVO.setSignon(signon);
//            Profile profile = new Profile();
//            accountVO.setProfile(profile);
//            Bannerdata bannerdata = new Bannerdata();
//            accountVO.setBannerdata(bannerdata);
//
//            accountVO.getAccount().setUsername(username);
//            accountVO.getAccount().setCountry(" ");
//            accountVO.getAccount().setEmail(" ");
//
//            accountVO.getAccount().setAddress1(" ");
//            accountVO.getAccount().setAddress2(" ");
//            accountVO.getAccount().setCity(" ");
//            accountVO.getAccount().setZip(" ");
//            accountVO.getAccount().setPhone(" ");
//
//            accountVO.getSignon().setUsername(username);
//            accountVO.getSignon().setPassword(" ");
//
//            accountVO.getProfile().setUsername(username);
//            accountVO.getProfile().setBannerOption(0);
//            accountVO.getProfile().setFavouriteCategoryId(" ");
//            accountVO.getProfile().setLanguagePreference(" ");
//            accountVO.getProfile().setListOption(0);
//
//            accountVO.getBannerdata().setBannername(" ");
//            accountVO.getBannerdata().setFavcategory(" ");
//
//            accountService.insertAccount(accountVO);
//        }
//    }
//
//    @GetMapping("/accountSearch")
//    @ResponseBody
//    public String accountSearch(){
//        return "{\"username\":\"a\",\"email\":\"abf\",\"firstName\":\"ab\",\"lastName\":\"asdasd\",\"status\":\"a\",\"address1\":\"a\",\"address2\":\"a\",\"city\":\"aa\",\"state\":\"a\",\"zip\":\"a\",\"country\":\"a\",\"phone\":\"a\"}";
//    }
//}
